<?php
namespace app\index\model;
use think\Model;
use think\Cache;
use think\Db;
use app\index\model\Nav;
use app\index\model\traits\ModelHasTime;




class Order extends Model
{
	use ModelHasTime;
	
	protected $autoWriteTimestamp = 'datetime';

	public function getDetail($id)
	{
		return self::field('order_id,title,order.money,order.action,nav_id,pack_id,user_id,id,know_phone,status,updated_time')
				->join('know_user','know_user.know_user_id=order.user_id')
				->where('order_id',$id)
				->find();
	}


	public function getUserData()
	{
		$user = user();
		$navData = Nav::getAllData();
		$navIds = array_column($navData, 'nav_id');
		foreach($navData as $v){
			$navData[$v['nav_id']] = ['icon' => $v['nav_icon'],'back'=> $v['nav_back']];
		}
		$data = self::field('id,title,order_id,nav_id,money,updated_time,status')
					->where('user_id', $user['id'])
					->where('nav_id', 'in', $navIds)
					->where('is_show', 1)
					->where(function($query){
						$query->where(['created_time'=>['>=',date('Y-m-d')]])->whereor('status', '1');
					})
					->order('updated_time desc')->paginate(20);
		return [$data, $navData];
	}

	
}